// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import androidx.compose.animation.Crossfade
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

fun main() = application {
    Window(onCloseRequest = ::exitApplication, title = "经典软件体系结构教学软件") {
        App()
    }
}

val PAGE_TITLES = listOf("KWIC转换", "主程序-子程序", "面向对象", "事件系统", "管道-过滤器")

@Composable
@Preview
fun App() {
    var selectedPage by remember { mutableStateOf(0) }
    MaterialTheme {
        Row {
            Column(modifier = Modifier.weight(0.3f)) {

                Text(
                    text = "主菜单",
                    textAlign = TextAlign.Center,
                    modifier = Modifier.fillMaxWidth().padding(vertical = 10.dp)
                )

                Box(modifier = Modifier.height(1.dp).fillMaxWidth().alpha(0.5f), contentAlignment = Alignment.Center) {
                    Box(modifier = Modifier.fillMaxWidth(0.65f).fillMaxHeight().background(Color.Gray))
                }

                PAGE_TITLES.forEachIndexed { index, title ->
                    val selected = index == selectedPage
                    TextButton(
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(60.dp), onClick = {
                            selectedPage = index
                        }) {
                        Text(text = title, color = if (selected) MaterialTheme.colors.primary else Color.Gray)
                    }

                }

            }


            Box(
                modifier = Modifier.width(2.dp).fillMaxHeight()
                    .background(brush = Brush.verticalGradient(listOf(Color.Gray, Color.White)))
            )

            Crossfade(modifier = Modifier.weight(0.7f).padding(15.dp), targetState = selectedPage) {
                when (it) {
                    0 -> {
                        TransformScreen()
                    }
                    else -> {
                        EducationScreen(it)
                    }
                }
            }

        }
    }
}
